package com.yl.auth.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.log.Log;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yl.auth.entity.Role;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yl.auth.entity.User;
import com.yl.auth.entity.Users;
import com.yl.auth.mapper.RoleMapper;
import com.yl.auth.mapper.UserMapper;
import com.yl.auth.mapper.UsersMapper;
import com.yl.auth.model.vo.UserVo;
import com.yl.auth.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yl.common.result.Result;
import com.yl.auth.utils.TokenUtils;
import com.yl.common.execption.GuiguException;
import com.yl.common.result.ResultCodeEnum;
import jdk.nashorn.internal.parser.Token;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ln
 * @since 2023-07-18
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;
    @Resource
    private RoleMapper roleMapper;

    @Resource
    private UsersMapper usersMapper;

    private static final Log LOG = Log.get();

    @Override
    public IPage<User> findAllUser(Page<User> page1) {
        return userMapper.findAllUser(page1);
    }

    @Override
    public void saveuser(Integer id,Integer uid) {
        userMapper.saveuser(id,uid);
    }

    @Override
    public void removeRole(Integer id) {
        roleMapper.removeRole(id);
    }



//    @Override
//    public Users login(Users users) {
//        Users userInfo = getUserInfo(users);
//        if(userInfo!=null) {
//            BeanUtil.copyProperties(userInfo,users,true);
//            //设置token
//            String token = TokenUtils.getToken(userInfo.getId().toString(), userInfo.getPassword());
//            users.setToken(token);
//            return users;
//        }else {
//            throw new GuiguException(ResultCodeEnum.SERVICE_ERROR);
//        }
//    }

    @Override
    public Users getPrimId(Integer id) {
        return usersMapper.getPrimId(id);
    }

//    private Users getUserInfo(Users user){
//        QueryWrapper<Users> wrapper = new QueryWrapper<>();
//        wrapper.eq("username",user.getUsername());
//        wrapper.eq("password",user.getPassword());
//        Users one;
//        try{
//            one = getOne(wrapper);
//        }catch (Exception e) {
//            LOG.error(e);
//            throw new GuiguException(ResultCodeEnum.CODE_600);
//        }
//        return one;
//    }

    @Override
    public User getZhangHaoSheZhi(Integer id) {
        return userMapper.getZhangHaoSheZhi(id);
    }



    @Override
    public void updateusers(Integer usersId) {
        usersMapper.updateusers(usersId);
    }
}
